package com.codyy.felix.webconsole.plugins.route.core.pojo;

import com.google.common.collect.Lists;

import java.util.Date;
import java.util.List;

/**
 * Fetched search progress results
 */
public class RouteProgress {

	private RouteParams params;

	private Date start;

	private Date stop;

	private long duration;

	private List<Object> steps = Lists.newArrayList();

	private List<IResult> results = Lists.newArrayList();

	public RouteProgress(RouteParams params) {
		this.params = params;
	}

	public void start() {
		this.start = new Date();
	}

	public void stop() {
		this.stop = new Date();
		this.duration = stop.getTime() - start.getTime();
	}

	public RouteParams getParams() {
		return params;
	}

	public Date getStart() {
		return start;
	}

	public Date getStop() {
		return stop;
	}

	public long getDuration() {
		return duration;
	}

	public void step(String message) {
		steps.add(message);
	}

	public List<Object> getSteps() {
		return steps;
	}

	public List<IResult> getResults() {
		return results;
	}

	/**
	 * Ensure that we have not too many results
	 */
	public void adjustResultsQuantity(int maxSize) {
		if (results.size() > maxSize) {
			results = results.subList(0, maxSize);
		}
	}
}
